package trees;

public class ReverseList {
    public ListNode reverseList(ListNode head) {
        ListNode prev = null;
        ListNode curr = head;
        while (curr != null) {
            ListNode next = curr.next;
            curr.next = prev;
            prev = curr;
            curr = next;
        }
        return prev;
    }

    public static void main(String[] args) {
        ListNode node = new ListNode(1);
        ListNode.add(2, node);
        ListNode.add(3, node);
        ListNode.add(4, node);
        ListNode.add(5, node);

        ReverseList reverseList = new ReverseList();
        reverseList.reverseList(node);
    }
}
